package com.tcoiss.log.controller;

import java.util.List;
import java.util.Arrays;

import com.tcoiss.common.core.domain.R;
import com.tcoiss.common.component.api.model.WorkLog;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tcoiss.common.log.annotation.Log;
import com.tcoiss.common.core.web.controller.BaseController;
import com.tcoiss.common.core.web.domain.AjaxResult;
import com.tcoiss.common.log.enums.BusinessType;
import com.tcoiss.common.security.annotation.PreAuthorize;
import com.tcoiss.log.service.IWorkExecuteLogService;
import com.tcoiss.common.core.web.page.TableDataInfo;

/**
 * 作业日志Controller
 * 
 * @author zw
 * @date 2021-05-07
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/workLog" )
public class WorkLogController extends BaseController {

    private final IWorkExecuteLogService iWorkExecuteLogService;

    /**
     * 查询作业日志列表
     */
    @PreAuthorize(hasPermi = "workLog:log:list")
    @GetMapping("/list")
    public TableDataInfo list(WorkLog workLog) {
        startPage();
        List<WorkLog> list = iWorkExecuteLogService.queryList(workLog);
        return getDataTable(list);
    }


    /**
     * 获取作业日志详细信息
     */
    @PreAuthorize(hasPermi = "workLog:log:query" )
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iWorkExecuteLogService.getById(id));
    }

    /**
     * 新增作业日志
     */
    //@PreAuthorize(hasPermi = "workLog:log:add" )
    //@Log(title = "作业日志" , businessType = BusinessType.INSERT)
    @PostMapping("/saveWorkLog")
    public R<Boolean> saveWorkLog(@RequestBody WorkLog workLog) {
        return R.ok(iWorkExecuteLogService.save(workLog));
    }

    /**
     * 修改作业日志
     */
    @PreAuthorize(hasPermi = "workLog:log:edit" )
    @Log(title = "作业日志" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WorkLog workLog) {
        return toAjax(iWorkExecuteLogService.updateById(workLog) ? 1 : 0);
    }

    /**
     * 删除作业日志
     */
    @PreAuthorize(hasPermi = "workLog:log:remove" )
    @Log(title = "作业日志" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iWorkExecuteLogService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
